# This example shows how to subscribe to changes of multiple monitored items, pull events, and display each change.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time
# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *
# Instantiate the client object
client = EasyUAClient()
# In order to use event pull, you must set a non-zero queue capacity upfront.
client.PullDataChangeNotificationQueueCapacity = 1000
print('Subscribing...')
client.SubscribeMultipleMonitoredItems([
EasyUAMonitoredItemArguments(
None,
UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10845'),
UAMonitoringParameters(1000)),
EasyUAMonitoredItemArguments(
None,
UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'),
UAMonitoringParameters(1000)),
EasyUAMonitoredItemArguments(
None,
UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10855'),
UAMonitoringParameters(1000)),
])
print('Processing data change events for 1 minute...')
endTime = time.time() + 60
while time.time() < endTime:
eventArgs = IEasyUAClientExtension.PullDataChangeNotification(client, 2*1000)
if eventArgs is not None:
# Handle the notification event
print(eventArgs)